package com.outsider.news.service;

import java.util.List;
import java.util.Set;

import com.jfinal.weixin.sdk.msg.out.News;
import com.jfinal.weixin.sdk.msg.out.OutMsg;
import com.jfinal.weixin.sdk.msg.out.OutNewsMsg;
import com.outsider.news.dao.Acfun;
import com.outsider.news.dao.BaseNews;
import com.outsider.news.dao.Keyword;
import com.outsider.news.dao.PhoenixNews;
import com.outsider.news.dao.Zhihu;
import com.outsider.util.Const;

public class NewsService {
	public List<BaseNews> getNews(Integer userID, Set<BaseNews> set, String key) {
		String[] keywords = getKeywords(userID);
		if (key.equals(Const.ZHIHU_NEWS))
			return Zhihu.dao.findKeyWordNews(keywords, set);
		else if (key.equals(Const.ACFUN_NEWS))
			return Acfun.dao.findKeyWordNews(keywords, set);
		else if (key.equals(Const.PHOENIX_NEWS))
			return PhoenixNews.dao.findKeyWordNews(keywords, set);
		return null;

	}

	private String[] getKeywords(Integer userID) {
		Keyword keyword = Keyword.dao.findById(userID);
		String[] keywords = null;
		if (null != keyword && null != keyword.getKeyWord() && keyword.getKeyWord().isEmpty() == false)
			keywords = keyword.getKeyWord().trim().split(" ");
		return keywords;
	}

}
